{% schema %}
{
  "name": "Boundless",
  "settings": [
     {
      "type": "text",
      "id": "boundless_title",
      "label": "Title",
      "default": "Boundless Living, Anytime, Anywhere"
    },
  ],
  "blocks": [
    {
      "type": "swiper_item",
      "name": "Swiper Item",
      "settings": [
        {
          "type": "url",
          "id": "image",
          "label": "Image",
        },
        {
          "type": "url",
          "id": "image_pc",
          "label": "Image PC (>=1280px)",
        },
        {
          "type": "text",
          "id": "title",
          "label": "Title",
          "default": "Cinema-Grade Entertainment"
        },
        {
          "type": "text",
          "id": "description",
          "label": "Description",
          "default": "Your personal theater. Stunning visuals, immersive sound—anywhere you are."
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "Default",
      "category": "Custom"
    }
  ]
}
{% endschema %}

{%- style -%}
    .box-{{ section.id }} {
        overflow: hidden;
      background: black;
      padding-bottom: 98px;
    }
       .box-{{ section.id }} .swiper {
          width: 100%;
          min-height: 510px;
          overflow: hidden;
        }

       .box-{{ section.id }} .swiper-slide {
          text-align: center;
          font-size: 18px; 
          display: flex;
          justify-content: center;
          align-items: center;
        }

       .box-{{ section.id }} .swiper-slide img {
          display: block;
          width: 100%;
          height: 100%;
          object-fit: cover;
        }

       .box-{{ section.id }} .swiper-slide {
          width: 80%;
         display: flex;
         flex-direction: column;
 opacity: 0.4;
          transition: opacity 0.5s;
        }

   .box-{{ section.id }} .swiper-slide.swiper-slide-active {
    opacity: 1;
  }

       .box-{{ section.id }} .swiper-pagination-{{ section.id }} {
          position: absolute;
          top: auto !important;
          bottom: 0px !important;
          left: 10% !important;
          width: 80% !important;
        }
      .box-{{ section.id }} .swiper-pagination-progressbar .swiper-pagination-progressbar-fill {
  background: #FFFFFF;
      }
    .box-{{ section.id }} .swiper-pagination-progressbar {
      background: rgba(255,255,255,0.2);
      border-radius: 4px;
      overflow: hidden;
    }
    .box-title-{{ section.id }} {
      width: 320px;
      font-family: HarmonyOS Sans;
      font-size: 36px;
      font-weight: bold;
      line-height: 120%;
      text-align: center;
      letter-spacing: -1.44px;
      color: #FFFFFF;
    }
  .swiper-item-title-{{ section.id }} {
    width: 100%;
    font-family: HarmonyOS Sans;
    font-size: 20px;
    font-weight: bold;
    line-height: 100%;
    letter-spacing: -0.8px;
    color: #FFFFFF;
    text-align: left;
  }
  .swiper-item-card-{{ section.id }} {
    width: 100%;
    border-radius: 20px;
    overflow: hidden;
  }
  .swiper-item-desc-{{ section.id }} {
    font-family: HarmonyOS Sans;
    font-size: 14px;
    font-weight: normal;
    line-height: 120%;
    letter-spacing: -0.56px;
    color: #FFFFFF;
    text-align: left;
        width: 100%;
  }
    .fixed-{{ section.id }} {
    position: fixed!important;
    top: 48px;
    left: 0;
    width: 100vw;
  }
  .fixed-box-{{ section.id }} {
       position: relative;
    min-height: 100vh;
    background: black;
  }
  .fixed-box-{{ section.id }}.active {
    height: 180vh;
  }
{%- endstyle -%}

<div class="fixed-box-{{ section.id }}" id="fixed-box-{{ section.id }}">
  <div class="box-{{ section.id }} position-relative" id="box-{{ section.id }}">
  <div class="box-title-{{ section.id }} pt-7 mb-6 anim mx-auto">{{ section.settings.boundless_title }}</div>
  <div class="swiper mySwiper-{{ section.id }} pb-5" id="mySwiper-{{ section.id }}">
    <div class="swiper-wrapper" style="transition-duration: 0ms; transition-delay: 0ms; transform: translate3d(39px, 0px, 0px);">
       {% for block in section.blocks %}
        <div class="swiper-slide" style="margin-right: 24px">
          <div class="swiper-item-card-{{ section.id }} mb-5">
            <img class="d-block d-xl-none" src="{{ block.settings.image }}" alt="Swiper Image"/> 
            <img class="d-none d-xl-block" src="{{ block.settings.image_pc }}" alt="Swiper Image"/> 
          </div>
          <div class="swiper-item-title-{{ section.id }} mb-2">
            {{ block.settings.title }}
          </div>
          <div class="swiper-item-desc-{{ section.id }}">
            {{ block.settings.description }}
          </div>
        </div>
      {% endfor %}
    </div>
    <div class="swiper-pagination-{{ section.id }}"></div>
  </div>
</div>
</div>


<script>
  document.addEventListener('DOMContentLoaded', function () {
    const swiper = new Swiper(".mySwiper-{{ section.id }}", {
        slidesPerView: "auto",
        centeredSlides: true,
        spaceBetween: 24,
        pagination: {
          el: ".swiper-pagination-{{ section.id }}",
          type: "progressbar",
        },
      });
    function addClassWhenInCenter() {
      const targetDiv = document.getElementById('fixed-box-{{ section.id }}');
      const targetDiv2 = document.getElementById('mySwiper-{{ section.id }}');
      let offsetTop = 232 - 56
      if (!targetDiv || !targetDiv2) return;
      if (window.innerWidth < 1280 ) {
        swiper.enable();
        targetDiv2.style.position = "relative";
        targetDiv.style.opacity = 1;
        return
      };
      const targetRect2 = targetDiv2.getBoundingClientRect();
      targetDiv.style.height = targetRect2.height * 3 + "px";
      const viewportHeight = window.innerHeight;
      const targetRect = targetDiv.getBoundingClientRect();
      const targetTop = targetRect.top;
      const targetBottom = targetRect.bottom;
       targetDiv2.style.maxWidth = targetRect.width + "px";
      if (targetRect2.height < window.innerHeight - 56 * 2) {
        offsetTop = (window.innerHeight - 56 * 2 - targetRect2.height) / 2 + 56
      } else {
        offsetTop = 80 - 56;
      }
      if (targetTop <= -232 - 120 + offsetTop) {
          targetDiv2.style.position = "fixed";
          targetDiv2.style.zIndex = "0";
          targetDiv2.style.top = offsetTop + "px";
          swiper.setProgress(((targetTop +120+232- offsetTop ) * -1) / (targetRect2.height * 2) * 2, 0);
        } else {
           targetDiv2.style.position = "relative";
        targetDiv2.style.top = "0px";
            swiper.setProgress(0, 0);
        }
                  if (targetBottom < -100) {
              targetDiv.style.opacity = 0;
            } else {
              targetDiv.style.opacity = 1;
            }
    }
   window.addEventListener('scroll', addClassWhenInCenter);
        addClassWhenInCenter();
  })
</script>

<style>
  @media screen and (min-width: 1280px) {
    .swiper-item-card-{{ section.id }} {
      height: 460px;
    }
    .box-title-{{ section.id }} {
      width: 632px;
      font-size: 70px;
      margin-bottom: 120px!important;
    }
           .box-{{ section.id }} .swiper-pagination-{{ section.id }} {
          position: absolute;
          top: auto !important;
          bottom: 0px !important;
          left: 50% !important;
          width: 1015px !important;
                 transform: translateX(-50%);
        }
           .box-{{ section.id }} .swiper-slide {
          width: 1015px;
         display: flex;
         flex-direction: column;
 opacity: 0.4;
          transition: opacity 0.5s;
        }
    .swiper-item-title {
      font-size: 24px;
    }
    .swiper-item-desc {
      font-size: 24px;
    }
  }
</style>
